// my_predictor.h
// Daan Raman, Xavier Smet
// This file represents a static predictor - it can either predict all branches taken,
// or non-taken.

#include <string>

class my_update : public branch_update {
public:
	unsigned int index;
};

class my_predictor : public branch_predictor {
public:
	
	#define HISTORY_LENGTH	10
	#define TABLE_BITS	10
	
	//Define variables for this predictor
	my_update u;
	branch_info bi;
	unsigned int history;
	unsigned char tab[1<<TABLE_BITS];
	
	//Keep track of the predictor we are currently using
	bool usingMetaPredictor;
	
	//This sets the jump direction of the prediction
	bool alwaysTaken;
	
	//Constructor for our predictor
	my_predictor (void) : history(0){
		printf("Filling tab table ... \n");
		memset(tab, 0, sizeof(tab));
	}
	
	//Make the prediction
	branch_update *predict (branch_info & b) {
		alwaysTaken = true;
		
		//Local reference to branch info argument
		bi = b;
		//Only predict in case we are dealing with an actual conditional branch.
		if (alwaysTaken) {
			//Branch is taken (prediction)
			u.direction_prediction (false);
		} else {
			//Branch is not taken (prediction)
			u.direction_prediction (true);
		}
		u.target_prediction (0);
		return &u;
	}
	
	//Get updates - this gives our predictor extra, new information
	void update (branch_update *u, bool taken, unsigned int target) {
		if (bi.br_flags & BR_CONDITIONAL) {
			if (taken) {
				//printf("Branch taken\n");
			} else {
				//printf("Branch NOT taken\n");
			}
		}
	}
};
